package com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.task;

import cn.hutool.core.collection.CollectionUtil;
import com.gee.spring.cloud.aerospace.simulate.core.satellite.telemetry.common.SateTraceContext;
import lombok.Data;

import java.util.List;

/**
 * @author gee
 * @since 2025/5/15 10:06
 */
@Data
public abstract class AbstractHandler implements Handler {

    private List<AbstractHandler> delegateTaskList;

    public AbstractHandler(List<AbstractHandler> delegateTaskList) {
        this.delegateTaskList = delegateTaskList;
    }

    @Override
    public boolean pause(SateTraceContext sateTraceContext, long simulateTime) {
        if (CollectionUtil.isNotEmpty(delegateTaskList)) {
            delegateTaskList.forEach(task -> task.pause(sateTraceContext, simulateTime));
        }
        return doPause(sateTraceContext, simulateTime);
    }


    @Override
    public boolean resume(SateTraceContext sateTraceContext, long simulateTime) {
        if (CollectionUtil.isNotEmpty(delegateTaskList)) {
            delegateTaskList.forEach(task -> task.resume(sateTraceContext, simulateTime));
        }
        return doResume(sateTraceContext, simulateTime);
    }


    @Override
    public boolean start(SateTraceContext sateTraceContext, long simulateTime) {
        if (CollectionUtil.isNotEmpty(delegateTaskList)) {
            delegateTaskList.forEach(task -> task.start(sateTraceContext, simulateTime));
        }
        return doStart(sateTraceContext, simulateTime);
    }

    @Override
    public boolean stop(SateTraceContext sateTraceContext, long simulateTime) {
        if (CollectionUtil.isNotEmpty(delegateTaskList)) {
            delegateTaskList.forEach(task -> task.stop(sateTraceContext, simulateTime));
        }
        return doStop(sateTraceContext, simulateTime);
    }
    protected abstract boolean doStart(SateTraceContext sateTraceContext, long simulateTime);

    protected boolean doStop(SateTraceContext sateTraceContext, long simulateTime){
        return true;
    };

    protected boolean doPause(SateTraceContext sateTraceContext, long simulateTime){
        return true;
    };

    protected boolean doResume(SateTraceContext sateTraceContext, long simulateTime){
        return true;
    };

}
